package com.zang.stackqueue;

import java.util.Stack;

/**
 * @author ZVerify
 * @since 2022/10/18 11:01
 **/
public class 用栈实现队列 {

    Stack<Integer> pushStack;
    Stack<Integer> popStack;

    public 用栈实现队列() {
        pushStack = new Stack<>();
        popStack = new Stack<>();

    }

    public void push(int x) {
        pushStack.push(x);
    }

    public int pop() {
        ifT();
        return popStack.pop();
    }

    public int peek() {
        ifT();
        return popStack.peek();
    }

    public boolean empty() {
        return pushStack.empty() && popStack.empty();
    }
    void ifT(){
        if (!pushStack.empty()) return;
        while (!pushStack.empty()){
            Integer pop = pushStack.pop();
            popStack.push(pop);
        }
    }
}
